package UIComponents
{
	import Classes.GameUtils.MyTipSprite;
	import Classes.GameUtils.ToolTip_Sprite;
	import Classes.staticinfo.Language;
	
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.filters.BitmapFilterQuality;
	import flash.filters.ColorMatrixFilter;
	import flash.filters.GlowFilter;

	/**
	 *选择性别与技能 
	 * @author 邓坚
	 * 
	 */	
	public class SelectSex_panel extends Sprite
	{
		
		private var _sex_panel:Sprite;		//性别面板
		private var _skill_panel:Sprite;	//技能面板
		private var _isPanel2:Boolean;		//是否是第二个面板
		private var _sex:uint=0;			//性别  男为1	女为0
		private var _skill:uint=0;			//技能  0为未选	1 2 3 4 为第几项
		public function SelectSex_panel()
		{
			init();
		}
		
		public function init():void
		{
			_sex_panel		=	(this.getChildByName("sex_panel") as Sprite);
			_skill_panel	=	(this.getChildByName("skill_panel") as Sprite);
			_skill_panel.visible = false;
			addListener();
		}
		
		public function addListener():void
		{
			_sex_panel.getChildByName("btn_n").addEventListener(MouseEvent.CLICK,clickN);
			_sex_panel.getChildByName("btn_n").addEventListener(MouseEvent.MOUSE_OVER,ono);
			_sex_panel.getChildByName("btn_l").addEventListener(MouseEvent.CLICK,clickL);
			_sex_panel.getChildByName("btn_l").addEventListener(MouseEvent.MOUSE_OVER,olo);
			
			_skill_panel.getChildByName("btn_break").addEventListener(MouseEvent.CLICK,clickBreak);
			
			_skill_panel.getChildByName("btn_item1").addEventListener(MouseEvent.MOUSE_DOWN,clickItem1);
			_skill_panel.getChildByName("btn_item2").addEventListener(MouseEvent.MOUSE_DOWN,clickItem2);
			_skill_panel.getChildByName("btn_item3").addEventListener(MouseEvent.MOUSE_DOWN,clickItem3);
			_skill_panel.getChildByName("btn_item4").addEventListener(MouseEvent.MOUSE_DOWN,clickItem4);
			
			//热感
			ToolTip_Sprite.getInstance().setTip(_skill_panel.getChildByName("btn_item1") as DisplayObject,new MyTipSprite(Language.selectSexWL),ToolTip_Sprite.DIRECTION_UP,true);
			ToolTip_Sprite.getInstance().setTip(_skill_panel.getChildByName("btn_item2") as DisplayObject,new MyTipSprite(Language.selectSexSD),ToolTip_Sprite.DIRECTION_UP,true);
			ToolTip_Sprite.getInstance().setTip(_skill_panel.getChildByName("btn_item3") as DisplayObject,new MyTipSprite(Language.selectSexHY),ToolTip_Sprite.DIRECTION_UP,true);
			ToolTip_Sprite.getInstance().setTip(_skill_panel.getChildByName("btn_item4") as DisplayObject,new MyTipSprite(Language.selectSexQF),ToolTip_Sprite.DIRECTION_UP,true);
			
			
			_skill_panel.getChildByName("btn_confirm").addEventListener(MouseEvent.CLICK,confirmHandler);
		}
		
		public function ono(e:Event):void
		{
			this.dispatchEvent(new Event("btnnOver",true));
		}
		
		public function olo(e:Event):void
		{
			this.dispatchEvent(new Event("btnlOver",true));
		}
		/**
		 *确认 
		 * @param e
		 */
		public function confirmHandler(e:Event):void
		{
			this.dispatchEvent(new Event("confirm",true));
		}
		
		public function clickItem1(e:Event):void
		{
			skill	=	1
		}
		public function clickItem2(e:Event):void
		{
			skill	=	2
		}
		public function clickItem3(e:Event):void
		{
			skill	=	3
		}
		public function clickItem4(e:Event):void
		{
			skill	=	4
		}
		
		public function clickBreak(e:Event):void
		{
			isPanel2	=	false;
		}
		
		public function clickN(e:Event):void
		{
			_sex	=	1;
			isPanel2	=  true;
		}
		
		public function clickL(e:Event):void
		{ 
			_sex	=	0;
			isPanel2	=  true;
		}
		
		public function set skill(value:uint):void
		{
			if(_skill==value)return;
			var filter:GlowFilter=new GlowFilter(0xffffff,0.8,10,10,2,BitmapFilterQuality.LOW);
			var filters:Array=[filter,new ColorMatrixFilter([2,0,0,0,0,0,2,0,0,0,0,0,2,0,0,0,0,0,1,0])];
//			trace((this._skill_panel.getChildByName("btn_item"+_skill) as SimpleButton).sg,this._skill_panel.getChildByName("btn_item"+_skill) as MovieClip);
			if(_skill!=value && _skill!=0){
			(this._skill_panel.getChildByName("btn_item"+_skill) as SimpleButton).enabled	=true;
			(this._skill_panel.getChildByName("btn_item"+_skill) as SimpleButton).filters=null;
			}
			_skill	=	value;
			(this._skill_panel.getChildByName("btn_item"+_skill) as SimpleButton).enabled	=false;
			(this._skill_panel.getChildByName("btn_item"+_skill) as SimpleButton).filters=filters;
			
			(this._skill_panel.getChildByName("btn_confirm") as SimpleButton).enabled	=true;
		}
		
		public function set isPanel2(value:Boolean):void
		{
			if(_isPanel2==value)return;
			if(value){
					_sex_panel.visible	=	false;
					_skill_panel.visible=	true;
					if(_skill==0)(this._skill_panel.getChildByName("btn_confirm") as SimpleButton).enabled	=false;
			}else{
				_sex_panel.visible	=	true;
				_skill_panel.visible=	false;
			}
			
			_isPanel2	=	value;
		}
		
		public function get sex():uint
		{
			return _sex;
		}
		public function get skill():uint
		{
			return _skill;
		}
		
		public function get btnN():Sprite
		{
			return _sex_panel.getChildByName("btn_n") as Sprite;
		}
		
		public function get btnL():Sprite
		{
			return _sex_panel.getChildByName("btn_l") as Sprite;
		}
	}
}